/*
 * 作者:熊猫
 * 日期:2017 - 3 - 19 9 - 2 - 39
 *
 */

package net.lainiao.morethread.Chapter7.demo7;

import java.util.Date;
import java.util.concurrent.ForkJoinTask;

/**
 * Created by Administrator on 2017/3/19.
 */
public abstract class MyWorkerTask extends ForkJoinTask<Void> {
    private String name;

    public MyWorkerTask(String name) {
        this.name = name;
    }

    @Override
    public Void getRawResult() {
        return null;
    }

    @Override
    protected void setRawResult(Void value) {

    }

    @Override
    protected boolean exec() {
        Date startTime=new Date();
        compute();
        Date endTime=new Date();
        long diff=endTime.getTime()-startTime.getTime();
        System.out.println("MyWorkerTask "+this.name+": "+diff+" Milliseconds to complete");
        return true;
    }

    public String getName() {
        return name;
    }

    protected abstract void compute();
}
